package cn.stylefeng.guns.modular.basic.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicOperate;
import cn.stylefeng.guns.modular.basic.mapper.BasicOperateMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicOperateParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicOperateResult;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.sys.modular.system.entity.Dept;
import cn.stylefeng.guns.sys.modular.system.service.DeptService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 运营部表（原系统：分公司表） 服务实现类
 */
@Service
public class BasicOperateServiceImpl extends ServiceImpl<BasicOperateMapper, BasicOperate> implements BasicOperateService {
    
    @Resource
    private DeptService deptService;

    @Override
    public void add(BasicOperateParam param){
        BasicOperate entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicOperateParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicOperateParam param){
        BasicOperate oldEntity = getOldEntity(param);
        BasicOperate newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicOperateResult findBySpec(BasicOperateParam param,Long operateId){
        return this.baseMapper.findBySpec(param, operateId);
    }

    @Override
    public List<BasicOperateResult> findListBySpec(BasicOperateParam param,Long operateId){
        return this.baseMapper.findListBySpec(param, operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicOperateParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param, condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicOperateParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicOperate getOldEntity(BasicOperateParam param) {
        return this.getById(getKey(param));
    }

    private BasicOperate getEntity(BasicOperateParam param) {
        BasicOperate entity = new BasicOperate();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<BasicOperate> findListByDeptId(Long deptId) {
		return this.baseMapper.findListByDeptId(deptId);
	}

	@Override
	public List<BasicOperateResult> findAvailableList(Long deptId, Long deliverId,Long operateId) {
		BasicOperateParam param = new BasicOperateParam();
		param.setDeptId(deptId);
		param.setDeliverId(deliverId);
        return this.baseMapper.findListBySpec(param, operateId);
	}

	@Override
	public List<BasicOperateResult> dayTotalOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalOrderCount(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> dayTotalOrderVolume(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalOrderVolume(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> dayTotalOrderFayunCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalOrderFayunCount(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> dayTotalFayunFenxi(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalFayunFenxi(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> dayTotalWeisongdaFenxi(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalWeisongdaFenxi(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> dayTotalWeiqianshouFenxi(BasicOperateParam basicOperateParam) {
		return this.baseMapper.dayTotalWeiqianshouFenxi(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalOrderCount(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalOrderVolume(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalOrderVolume(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalHuanjieFenxi(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalHuanjieFenxi(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalFayunOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalFayunOrderCount(basicOperateParam);
	}

	@Override
	public BasicOperateResult monthTotalFayunOrderCountById(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalFayunOrderCountById(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalSongdaOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalSongdaOrderCount(basicOperateParam);
	}

	@Override
	public BasicOperateResult monthTotalSongdaOrderCountById(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalSongdaOrderCountById(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> monthTotalQianshouOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalQianshouOrderCount(basicOperateParam);
	}

	@Override
	public BasicOperateResult monthTotalQianshouOrderCountById(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalQianshouOrderCountById(basicOperateParam);
	}

	@Override
	public BasicOperateResult monthTotalQianOrderCountTimeById(BasicOperateParam basicOperateParam2) {
		return this.baseMapper.monthTotalQianOrderCountTimeById(basicOperateParam2);
	}

	@Override
	public List<BasicOperateResult> monthTotalQianOrderCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalQianOrderCount(basicOperateParam);
	}

	@Override
	public BasicOperateResult monthTotalFayunCount(BasicOperateParam basicOperateParam) {
		return this.baseMapper.monthTotalFayunCount(basicOperateParam);
	}

	@Override
	public List<BasicOperateResult> findTransportListBySpec(BasicOperateParam basicOperateParam, String month) {
		return this.baseMapper.findTransportListBySpec(basicOperateParam,month);
	}

	@Override
	public Integer addReturnId(BasicOperateParam basicOperateParam) {
		return this.baseMapper.addReturnId(basicOperateParam);
	}

}
